﻿using System;
using System.Threading.Tasks;

namespace ServerUtils
{
    public class FuncAsyncOperation<TResult> : IAsyncOperation<TResult>
    {
        private Func<Task<TResult>> func;

        public FuncAsyncOperation(string name, object request, Func<Task<TResult>> func)
        {
            this.Name = name;
            this.Request = request;
            this.func = func;
        }

        public long OperationId { get; set; }

        public string Name { get; private set; }

        public object Request { get; private set; }

        public async Task<TResult> ExecuteAsync()
        {
            return await this.func();
        }
    }
}
